package Core 
{
	import com.greensock.TweenLite;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import Fonts.CalibriEmbed;
	
	/**
	 * ...
	 * @author Serg de Adelantado
	 */
	public class IconListItem extends Sprite 
	{	
		protected const COLOR:uint = 0xC2D6EB;
		protected const COLOR_SELECTED:uint = 0x6699CC;
		protected const TEXT_COLOR:uint = 0x333333;
		protected const TEXT_COLOR_DISABLED:uint = 0x999999;		
		protected var FEnabled:Boolean;
		protected var FText:TextField;
		protected var FBackground:Sprite;
		protected var FObjectID:int;
		
		public function IconListItem(AText:String) 
		{
			FText = new TextField();
			FText.textColor = TEXT_COLOR;
			FText.autoSize = TextFieldAutoSize.LEFT;			
			var vFormat:TextFormat = new TextFormat();
			vFormat.font = new CalibriEmbed().fontName;						
			FText.defaultTextFormat = vFormat;
			FText.selectable = false;
			FText.mouseEnabled = false;
			FText.text = AText;			
			FBackground = new Sprite();
			FBackground.mouseEnabled = false;
			FBackground.alpha = 1;
			FBackground.scaleX = 0;
			addChild(FBackground);			
			addChild(FText);			
			Width = FText.width;
			FEnabled = true;
			addEventListener(MouseEvent.MOUSE_OVER, OnMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, OnMouseOut);
		}
		
		private function OnMouseOver(e:MouseEvent):void 
		{
			if(FEnabled)
				TweenLite.to(FBackground, 0.5, { scaleX: 1 } );
		}
		
		private function OnMouseOut(e:MouseEvent):void 
		{				
			if(FEnabled)
				TweenLite.to(FBackground, 0.5, { scaleX: 0 } );
		}
		
		public function set Width(AWidth:int):void
		{
			graphics.beginFill(COLOR);
			graphics.drawRect(0, 0, AWidth, FText.height);
			graphics.endFill();
			
			FBackground.graphics.beginFill(COLOR_SELECTED);
			FBackground.graphics.drawRect(0, 0, AWidth, FText.height);
			FBackground.graphics.endFill();
		}
		
		public function set Text(AText:String):void 
		{
			FText.text = AText;
		}
			
		public function get Text():String
		{
			return FText.text;
		}
		
		public function set Enabled(AEnabled:Boolean):void
		{
			FEnabled = AEnabled;
			mouseEnabled = FEnabled;
			mouseChildren = FEnabled;
			TweenLite.killTweensOf(FBackground);
			FBackground.scaleX = 0;
			if (!FEnabled)
			{
				FText.textColor = TEXT_COLOR_DISABLED;				
			}
			else
				FText.textColor = TEXT_COLOR;
			useHandCursor = FEnabled;
			buttonMode = FEnabled;						
		}
		
		public function get ObjectID():int 
		{
			return FObjectID;
		}
		
		public function set ObjectID(AObjectID:int):void 
		{
			FObjectID = AObjectID;
		}
	}
}